#include <gtest/gtest.h>
#include "helper/transaction/Transaction.h"


TEST(TransactionTest, use){
  {
    helper::transaction::Transaction trans;
    ASSERT_TRUE(trans.isInited());
    ASSERT_EQ(std::errc::operation_not_permitted, trans.commit());
    ASSERT_EQ(std::errc::operation_not_permitted, trans.rollback());

    ASSERT_EQ(0, trans.begin().value());
    ASSERT_TRUE(trans.isStarted());
    ASSERT_EQ(0, trans.commit().value());
    ASSERT_TRUE(trans.isCommitted());
  }
  {
    helper::transaction::Transaction trans;
    ASSERT_TRUE(trans.isInited());
    ASSERT_EQ(0, trans.begin().value());
    ASSERT_TRUE(trans.isStarted());
    ASSERT_EQ(0, trans.rollback().value());
    ASSERT_TRUE(trans.isRollbacked());
  }
}

TEST(ScopedTransactionTest, use){
  std::unique_ptr<helper::transaction::ITransaction> trans = std::make_unique<helper::transaction::Transaction>();
  helper::transaction::ScopeTransaction st(std::move(trans));  

  ASSERT_EQ(0, st.rollback().value());
}
